//Sun Oct  9 13:15:38 PDT 2011
import java.util.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;
import java.awt.geom.*;

public class bloggoDocStructure {

	public Node rootA;
	public Node rootB;

	public String compare(String[] docA, String[] docB) {
		rootA = buildTree(concatenation(docA));
		rootB = buildTree(concatenation(docB));
		display(rootA);
		return "";
	}

	public void display(Node node) {
		if (node == null)
			return;
		System.out.print(node.data + " : ");
		for (int i = 0; i < node.next.size(); i++)
			System.out.print(node.next.get(i).data + ", ");
		System.out.println();
		for (int i = 0; i < node.next.size(); i++)
			display(node.next.get(i));
	}

	public Node buildTree(String s) {
		Node node = new Node();
		String s1 = extract(s);
		node.data = s1;
		String str = s.substring(s1.length(), s.length() - s1.length() - 1);
		while (str.length() > 0) {
			String tmp1 = extract(str);
			String tmp2 = "</" + tmp1.substring(1);
			int idx = str.indexOf(tmp2);
			String temp = str.substring(0, idx + tmp2.length());
			if (temp.length() > 0)
				node.next.add(buildTree(temp));
			str = str.substring(temp.length());
		}
		return node;
	}

	public String extract(String s) {
		if (s == null || s.length() == 0)
			return null;
		int idx1 = s.indexOf(">");
		String s1 = s.substring(0, idx1 + 1);
		// String s2 = "</" + s.substring(1, idx1) + ">";
		// int idx2 = s.indexOf(s2);
		return s1;
	}

	public String concatenation(String[] A) {
		String str = "";
		boolean flag = false;
		for (int i = 0; i < A.length; i++)
			for (int j = 0; j < A[i].length(); j++)
				if (A[i].charAt(j) == '<') {
					str += A[i].charAt(j);
					flag = true;
				} else if (A[i].charAt(j) == '>') {
					flag = false;
					str += A[i].charAt(j);
				} else if (flag)
					str += A[i].charAt(j);
		return str;
	}

	 public static void main(String[] args)
	{
		long time;
		String answer;
		boolean errors = false;
		String desiredAnswer;
		
		
		time = System.currentTimeMillis();
		answer = new bloggoDocStructure().compare(new String[]{"<html> <h1>Snapping Turtles</h1> <ul> <li> <h2>", "Common Snapping Turtle (<i>Chelydra serpentina</i>", ") </h2> <p> With its dark coloring, sinuous neck,", "and swift lunging motion, Chelydra serpentina is a",  "n adept hunter. </p><p> The snapping turtle rarely", "basks. </p><p> Snapping turtle populations are jeo", "pardized by automobile traffic.   </", "p>    </li> <li> <h2> Alligator Snapping Turtle (",  "<i>Macroclemys temminckii</i>) </h2> <p> Like the", " common snapping turtle, the alligator snapping ", "turtle has a massive head.</p><p>This is the lar", "gest freshwater turtle. A tubular pink append", "age grows from its mouth.</p>   <",  "/li> </ul> </html>"}, new String[]{" <html> turtles <h1> snapping </h1> <ul> <li> <h2", "> common <i> chelydra serpentina </i> </h2> <p>", "hunter </p> (adept?) <p> rarely basks </p> (hmm)", "<p> jeopardized by traffic </p></li>", "<li> often confused with... <h2> alligator snapp", "ing turtle <i>macroclemys temminckii</i> </h2>", "<p> massive head </p> big! <p>", "largest freshwater turtle. pink wormlike thing <",  "/p></li></ul></html>  "});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = "equivalent";
		System.out.println("Your answer:");
		System.out.println("\t\"" + answer + "\"");
		System.out.println("Desired answer:");
		System.out.println("\t\"" + desiredAnswer + "\"");
		if (!answer.equals(desiredAnswer))
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		time = System.currentTimeMillis();
		answer = new bloggoDocStructure().compare(new String[]{" <html> turtles <h1> snapping </h1> <ul> <li> <h2", "> common <i> chelydra serpentina </i> </h2> <p>", "hunter </p> (adept?) <p> rarely basks </p> (hmm)", "<p> jeopardized by traffic </p></li>", "<li> often confused with... <h2> alligator snapp", "ing turtle <i>macroclemys temminckii</i> </h2>", "<p> massive head </p> big! <p>", "largest freshwater turtle. pink wormlike thing <",  "/p></li></ul></html>  "}, new String[]{"<html><h1></h1><ul><li><h2><i></i></h2><p></p><p>", "</p><p></p></li><li><h2><i></i></h2><p></p><p></p", "></li></ul></html>"});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = "equivalent";
		System.out.println("Your answer:");
		System.out.println("\t\"" + answer + "\"");
		System.out.println("Desired answer:");
		System.out.println("\t\"" + desiredAnswer + "\"");
		if (!answer.equals(desiredAnswer))
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		time = System.currentTimeMillis();
		answer = new bloggoDocStructure().compare(new String[]{"<html><h1></h1><ul><li><h2><i></i></h2><p></p><p>", "</p><p></p></li><li><h2><i></i></h2><p></p><p></p", "></li></ul></html>"}, new String[]{" <html> snapping turtles <ul> <li> common ", "snapping turtle, chelydra serpentina <p>", "hunter </p> <p> rarely basks </p> ", "<p> jeopardized by traffic </p></li>", "<li> often confused with... <h2> alligator snapp", "ing turtle <i>macroclemys temminckii</i> </h2>", "<p> massive head; largest freshwater turtle;", "pink wormlike appendage lures fish </p>", "</li></ul></html>  "});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = "outtree 4";
		System.out.println("Your answer:");
		System.out.println("\t\"" + answer + "\"");
		System.out.println("Desired answer:");
		System.out.println("\t\"" + desiredAnswer + "\"");
		if (!answer.equals(desiredAnswer))
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		time = System.currentTimeMillis();
		answer = new bloggoDocStructure().compare(new String[]{"<html><h1></h1><ul><li><h2><i></i></h2><p></p><p>", "</p><p></p></li><li><h2><i></i></h2><p></p><p></p", "></li></ul></html>"}, new String[]{" <html> turtles <h1> snapping </h1> <ul> <li> <h2", "> common <i> chelydra serpentina </i> </h2> <p>", "hunter </p> <p> rarely basks <h3>", "<i>almost</i> <b>never</b> </h3> </p>", "<p> jeopardized by traffic </p></li>", "<li> often confused with... <h2> alligator snapp", "ing turtle <i>macroclemys temminckii</i> </h2>", "<p> massive head </p> big! <p>", "largest freshwater turtle. </p> <p> <b>pink</b>", " <b>wormlike</b> lure in mouth </p> <p> imposing", "sight on land or water </p> </li></ul></html>  "});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = "intree 7";
		System.out.println("Your answer:");
		System.out.println("\t\"" + answer + "\"");
		System.out.println("Desired answer:");
		System.out.println("\t\"" + desiredAnswer + "\"");
		if (!answer.equals(desiredAnswer))
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		time = System.currentTimeMillis();
		answer = new bloggoDocStructure().compare(new String[]{"<html><h1></h1><ul><li><h2><i></i></h2><p></p><p>", "</p><p></p></li><li><h2><i></i></h2><p></p><p></p", "></li></ul></html>"}, new String[]{"<html><ul><li><h2><i></i></h2><p></p><p>", "</p><p></p></li><li><h2><i></i></h2><p></p><p></p", "></li></ul><h1></h1></html>"});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = "incompatible";
		System.out.println("Your answer:");
		System.out.println("\t\"" + answer + "\"");
		System.out.println("Desired answer:");
		System.out.println("\t\"" + desiredAnswer + "\"");
		if (!answer.equals(desiredAnswer))
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		time = System.currentTimeMillis();
		answer = new bloggoDocStructure().compare(new String[]{"<html></html>"}, new String[]{"<html><html><html></html><html></html><ul>", "</ul><ol></ol></html></html>"});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = "intree 5";
		System.out.println("Your answer:");
		System.out.println("\t\"" + answer + "\"");
		System.out.println("Desired answer:");
		System.out.println("\t\"" + desiredAnswer + "\"");
		if (!answer.equals(desiredAnswer))
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		time = System.currentTimeMillis();
		answer = new bloggoDocStructure().compare(new String[]{"<html><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><b></b></html>"}, new String[]{"<html><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p><p></p>", "<p></p><p></p><p></p><p></p><p></p><p></p></html>"});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = "incompatible";
		System.out.println("Your answer:");
		System.out.println("\t\"" + answer + "\"");
		System.out.println("Desired answer:");
		System.out.println("\t\"" + desiredAnswer + "\"");
		if (!answer.equals(desiredAnswer))
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		
		
		if (errors)
			System.out.println("Some of the test cases had errors :-(");
		else
			System.out.println("You're a stud (at least on the test data)! :-D ");
	}

}

class Node {
	public String data;
	public List<Node> next;

	public Node() {
		this.data = "";
		this.next = new ArrayList<Node>();
	}
}
// Powered by [KawigiEdit] 2.0!
